package gewu.suleju.util;

import gewu.suleju.dao.iml.IHouseFeatureDao;
import gewu.suleju.dao.iml.IHousePicDao;
import gewu.suleju.model.pojo.HouseInfor;
import gewu.suleju.model.pojo.HousePic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class FindUtil {
    @Autowired
    private IHouseFeatureDao houseFeatureDao;

    @Autowired
    private IHousePicDao housePicDao;

    public List<String> findType(HouseInfor houseInfor) {
        Integer num = new Integer(houseInfor.getHouseFeatureId().trim());
        List<String> houseTypes = new ArrayList<>();

        while (num != 0){
            houseTypes.add(houseFeatureDao.findByIdEquals(num % 10).getType());
            num /= 10;
        }

        return houseTypes;
    }

    public List<String> findPicture(HouseInfor houseInfor) {
        List<String> housePics = new ArrayList<>();

        for(HousePic housePic:housePicDao.findByHouseInforIdAndIsStatus(houseInfor.getId(),1)) {
            housePics.add(housePic.getHousePicAddress().trim());
        }

        return housePics;
    }
}
